//
// Created by meng on 24-11-6.
//

#ifndef LOGICSYSTEM_H
#define LOGICSYSTEM_H

#include <map>

#include "Singleton.h"
#include "Session.h"
#include "Const.h"

typedef function<void(shared_ptr<Session> session, short msg_id, string msg_data)> FunCallBack;

class LogicSystem : public Singleton<LogicSystem> {
    friend class Singleton<LogicSystem>;

public:
    ~LogicSystem();

    void PostMsgToQueue(const std::shared_ptr<LogicNode> &msg);

private:
    LogicSystem();

    void DealMsg();

    void RegisterCallBacks();

    void HelloWordCallBack(const shared_ptr<Session> &, short msg_id, const string &msg_data);

    std::thread _worker_thread;
    std::queue<shared_ptr<LogicNode> > _msg_que;
    std::mutex _mutex;
    std::condition_variable _consume;
    bool _b_stop;
    map<short, FunCallBack> _fun_callbacks;
};


#endif //LOGICSYSTEM_H
